# -*- coding:utf-8 -*-

from enum import Enum


class SvrType(Enum):
    FASTAPI = 100
    LESS = 600


class HTTP:
    class STATUS_CODE:
        """
        https://www.runoob.com/http/http-status-codes.html
        """

        # 请求成功。一般用于GET与POST请求
        OK = 200

        # 服务器内部错误，无法完成请求
        INTERNAL_SERVER_ERROR = 500


class Result:
    FAIL = -1
    SUCCESS = 0

    def __init__(self, **kwargs):
        self.code = kwargs.get('code', Result.FAIL)
        self.message = kwargs.get('message', '')
        self.exts = kwargs.get('exts', {})
        self.trace = kwargs.get('trace', [])

    def format(self):
        result = {
            'code': self.code,
            'message': self.message
        }

        if self.code != Result.SUCCESS and self.trace:
            result['trace'] = self.trace

        if self.exts:
            result['exts'] = self.exts

        return result

    def __str__(self):
        return format()

    def __repr__(self):
        return str(format())


class Context:
    def __init__(self):
        pass
